from datetime import date, timedelta
from typing import List
from common.enum.strategy_group_enum import StrategyGroup
from common.enum.strategy_type_enum import StrategyType
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_assessment import RiskAssessment
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_stock_day import StrategyStockDay
from service.strategy.base_strategy import BaseStrategy


class IsWednesdayStrategy(BaseStrategy):
    """
    判断最近的一个交易日是否为周三策略。
    """

    def analyze(self, trade_info_list: List[StrategyStockDay]) -> RiskAssessment:
        """
        分析最近的一个交易日是否为周三。
        """
        # 默认值
        node_point = 0
        description = "最近的交易日不是周三。"

        # 检查是否有交易日数据
        if trade_info_list:
            # 获取最近一个交易日的信息
            latest_trade_info = trade_info_list[-1]
            latest_date = latest_trade_info.trade_date  # 假设为 datetime.date 类型

            # 判断最近交易日是否为周三
            if latest_date.weekday() == 2:  # 2 表示周三
                node_point = 3
                description = "最近的交易日为周三，符合策略条件，得 3 分。"

        # 返回风险评估结果
        return RiskAssessment(
            stock_code=trade_info_list[0].stock_code if trade_info_list else "未知",
            description=description,
            config=self.strategyConfig(),
            node_point=node_point,
        )

    def strategyConfig(self) -> dict:
        """
        返回策略的配置
        """
        return StrategyInfoMetadata(
            strategy_code="is_wednesday",
            strategy_name="最近交易日是否为周三策略",
            strategy_group=StrategyGroup.RISK,
            strategy_type=StrategyType.TIME_POINT,
            analysis_day=1,
            strategy_level=1,
        )
